package com.edevp.modules.order.web;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.edevp.common.core.dto.R;
import com.edevp.modules.order.service.OrderService;
import com.edevp.modules.user.dto.UserInfoDTO;
import com.edevp.modules.user.feign.UserFeignClient;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Lean
 */
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrderController {

    private final UserFeignClient userFeignClient;
    private final OrderService orderService;

    /**
     * 配置热点资源名称是hot
     */
    @SentinelResource("hot")
    @GetMapping("/{id}")
    public String get(@PathVariable("id") String id) {
        R<UserInfoDTO> result = userFeignClient.getUserInfo(id);
        return result.getData().getName()+"的订单";
    }

    @GetMapping("/query")
    public String queryOrder(){
        // 1.查询商品
        orderService.queryGoods();
        // 2. 查询订单
        System.out.println("查询订单");
        return "查询订单成功";
    }

    @GetMapping("/save")
    public String saveOrder(){
        // 1.查询商品
        orderService.queryGoods();
        // 2. 新增订单
        System.out.println("新增订单");
        return "新增订单成功";
    }

    @GetMapping("/update")
    public String updateOrder(){
        return "更新订单成功";
    }
}
